<script type="text/javascript">
		optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>

<?php
    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct();
?>
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
	<div class="no-display">
		<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
		<input type="hidden" name="related_product" id="related-products-field" value="" />
	</div>
	<div id="product-shop">
		<div class="product-options" id="product-options-wrapper" style="margin:0">
			<div class="product-name">
                <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
            </div>
				<?php $_associatedProducts = $this->getAssociatedProducts() ?>
				<?php if($_product->isSaleable() && count($_associatedProducts)): ?>
					<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
				<?php else: ?>
					<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
				<?php endif; ?>
				<?php echo $this->getChildHtml('product_type_data_extra') ?>
				<table class="data-table grouped-items-table" id="super-product-table">
					<col />
					<col />
					<col width="1" />
					<thead>
						<tr>
							<th><?php echo $this->__('Product Name') ?></th>
							<th class="a-right"><?php echo $this->__('Price') ?></th>
							<?php if ($_product->isSaleable()): ?>
							<th class="a-center"><?php echo $this->__('Qty') ?></th>
							<?php endif; ?>
						</tr>
					</thead>
					<tbody>
					<?php if (count($_associatedProducts)): ?>
					<?php foreach ($_associatedProducts as $_item): 
							$qty = (int)$_item->getQty();	
							$id = $_item->getId();
							$_product = Mage::getModel('catalog/product')->load($id);
							$max_sale_qty = $_product->getStockItem()->getMaxSaleQty();
							$min_sale_qty = $_product->getStockItem()->getMinSaleQty();
							$qtyStock   = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
							
							if($qty != 0){			
								$temp0 = $max_sale_qty - $qty;
								$temp1 = $qtyStock - $qty;
								$temp2 = $qty - $min_sale_qty;
								if($temp0 < 0 || $temp1 < 0 || $temp2 < 0){
									$temp = 1;
								}
							}else{
								$temp = 0;
							}						
					?>
						<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
						<tr>
							<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
							<td class="a-right">
								<?php echo $this->getPriceHtml($_item, true) ?>
								<?php echo $this->getTierPriceHtml($_item) ?>
							</td>
							<?php if ($_product->isSaleable()): ?>
							<td class="a-center">
							<?php if ($_item->isSaleable() && $qty >= 0) : ?>
								<input type="text" id="qty<?php echo $_item->getId() ?>" name="super_group[<?php echo $_item->getId() ?>]"  value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="grounped-pro input-text qty" />
								<input type="hidden" id="min_qty_stock<?php echo $_item->getId() ?>" name="min_qty_stock" value="<?php echo $min_sale_qty;?>"/>						
								<input type="hidden" id="max_qty_stock<?php echo $_item->getId() ?>" name="max_qty_stock" value="<?php echo $max_sale_qty; ?>"/>
								<input type="hidden" id="qty_stock<?php echo $_item->getId() ?>" name="qty_stock" value="<?php echo $qtyStock; ?>"/>
								<input type="hidden" id="cur_pro_name<?php echo $_item->getId() ?>" name="cur_pro_name" value="<?php echo $this->escapeHtml($_item->getName()); ?>"/>
								<input type="hidden" id="re<?php echo $_item->getId() ?>" name="re<?php echo $_item->getId() ?>" class="re" value="<?php if($temp==1){ echo $this->__("Quantity '".$this->escapeHtml($_item->getName())."' invalid! Quantity must: > Min: ".$min_sale_qty.", and < Max: ".$max_sale_qty.", and < Inventory: ".$qtyStock); } ?>"/>
							<?php else: ?>
								<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
							<?php endif; ?>
							</td>
							<?php endif; ?>
						</tr>
					<?php endforeach; ?>

					<?php else: ?>
					   <tr>
						   <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
					   </tr>
					<?php endif; ?>
					</tbody>
				</table>
		</div>
	</div>
		<div style="margin:10px 0px 0px 0px">
			<?php echo $this->getChildHtml('addtocart');?>
			<a href="javascript:void(0);" id="btcancel" onclick = "$('product_addtocart_form').remove();$('options').setStyle({display:'none'});">
				<?php echo $this->__('Cancel')?>
			</a>
		</div>
		<script type="text/javascript">decorateTable('super-product-table')</script>
</form>